package com.shy.controller;

import com.alibaba.excel.EasyExcel;
import com.shy.entity.Customer;
import com.shy.service.CustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.IOException;
import java.util.List;

@Api(tags = "下载接口管理")
@Controller
@RequestMapping("/api/download")
public class DownloadController {
    @Resource
    private CustomerService customerService;

    @ApiOperation("导出客户文件")
    @GetMapping("/exportExcel/{ids}")
    public void downloadExcel(HttpServletResponse response,@PathVariable List<Integer> ids) throws IOException {
        //查询所有客户信息
        List<Customer> customerList =customerService.queryCustomerLists(ids);
        //导出客户信息
        response.setHeader("Content-Disposition", "attachment;filename=customer.xlsx");
        EasyExcel.write(response.getOutputStream(),Customer.class).sheet("客户信息").doWrite(customerList);
    }
    @ApiOperation("导出客户文件")
    @GetMapping("/exportExcel")
    public void downloadExcel(HttpServletResponse response) throws IOException {
        //查询所有客户信息
        List<Customer> customerList =customerService.queryCustomerList();
        //导出客户信息
        response.setHeader("Content-Disposition", "attachment;filename=customer.xlsx");
        EasyExcel.write(response.getOutputStream(),Customer.class).sheet("客户信息").doWrite(customerList);
    }
}